package com.wf.smartcomm.server.client.action;

import java.util.HashMap;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ModelDriven;
import com.wf.smartcomm.server.bean.User;
import com.wf.smartcomm.server.response.ResponseCode;
import com.wf.smartcomm.server.service.ShopService;
import com.wf.smartcomm.server.service.UserService;

@Controller
@Scope("prototype")
public class ShopAction extends BaseAction implements ModelDriven<User>{
	
	private User user = new User();
	
	@Resource
	private ShopService shopServiceImpl;
	
	@Resource
	private UserService userServiceImpl;
	
	public void listByType() throws Exception{
		String type = request.getParameter("type");
		user = userServiceImpl.getUserById(user.getObjectId());
		shopServiceImpl.listByType(user.getLoginVillage(), type, page);
		HashMap<String,Object> map = new HashMap<String,Object>();
		map.put("code", ResponseCode.OK);
		map.put("data", page.getDataList());
		printJsonData(gson.toJson(map));
	}
	
	public void listByKey() throws Exception{
		String key = request.getParameter("key");
		user = userServiceImpl.getUserById(user.getObjectId());
		shopServiceImpl.query(user.getLoginVillage(), key, page);
		HashMap<String,Object> map = new HashMap<String,Object>();
		map.put("code", ResponseCode.OK);
		map.put("data", page.getDataList());
		printJsonData(gson.toJson(map));
	}
	
	

	@Override
	public User getModel() {
		// TODO Auto-generated method stub
		return user;
	}
}
